package StackAndQueue;

import java.util.LinkedList;

public class p1700无法吃午餐的学生数量 {
    class Solution {
        public int countStudents(int[] students, int[] sandwiches) {
            int like0 = 0;
            int like1 = 0;
            for (int i = 0; i < students.length; i++) {
                if (students[i] == 0){
                    like0++;
                } else {
                    like1++;
                }
            }
            int count = 0;
            for (int sandwich : sandwiches) {
                if (like0 <= 0 && sandwich == 0) {
                    break;
                } else if (like1 <= 0 && sandwich == 1) {
                    break;
                } else if (like0 > 0 && sandwich == 0) {
                    like0--;
                    count++;
                } else if (like1 > 0 && sandwich == 1) {
                    like1--;
                    count++;
                }
            }
            return students.length - count;
        }
    }
}
